package com.markerhub.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 * 用于自动生成API文档 - 兼容Swagger 2.9.2版本
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 创建API文档的主要配置
     */
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)
                .groupName("消防巡检系统")
                .select()
                // 指定要扫描的包路径
                .apis(RequestHandlerSelectors.basePackage("com.markerhub.controller"))
                // 指定要生成文档的路径规则
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置API文档的基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("消防巡检系统API文档")
                .description("基于Spring Boot的消防巡检系统API接口文档")
                .version("1.0.0")
                .contact(new Contact("技术团队", "http://localhost:8081", "support@example.com"))
                .build();
    }
}